﻿namespace Sidvall.LogManager.Net.Services.V1
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class LogScopeItem : global::Sidvall.Data.ServiceDataRowBase, global::Sidvall.LogManager.Data.ILogScopeItem
    {
        #region Public Members

        #region CreatedTime

        private System.DateTime _CreatedTime;
        partial void OnBeforeCreatedTimePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.DateTime> eventData);
        partial void OnAfterCreatedTimePropertyChanged();
        public System.DateTime CreatedTime
        { 
            get
            {
                return _CreatedTime;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _CreatedTime = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.DateTime> eventData = new Sidvall.Business.PropertyChangeEventData<System.DateTime>(value, _CreatedTime);
                    OnBeforeCreatedTimePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("CreatedTime", eventData.Value, true, true);
                        OnAfterCreatedTimePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region EventTypeId

        private global::Sidvall.Logging.EventType _EventTypeId;
        partial void OnBeforeEventTypeIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<global::Sidvall.Logging.EventType> eventData);
        partial void OnAfterEventTypeIdPropertyChanged();
        public global::Sidvall.Logging.EventType EventTypeId
        { 
            get
            {
                return _EventTypeId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _EventTypeId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<global::Sidvall.Logging.EventType> eventData = new Sidvall.Business.PropertyChangeEventData<global::Sidvall.Logging.EventType>(value, _EventTypeId);
                    OnBeforeEventTypeIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("EventTypeId", eventData.Value, true, true);
                        OnAfterEventTypeIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region IdentityAuthenticationType

        private string _IdentityAuthenticationType;
        partial void OnBeforeIdentityAuthenticationTypePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterIdentityAuthenticationTypePropertyChanged();
        public string IdentityAuthenticationType
        { 
            get
            {
                return _IdentityAuthenticationType;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _IdentityAuthenticationType = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _IdentityAuthenticationType);
                    OnBeforeIdentityAuthenticationTypePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("IdentityAuthenticationType", eventData.Value, true, true);
                        OnAfterIdentityAuthenticationTypePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region IdentityName

        private string _IdentityName;
        partial void OnBeforeIdentityNamePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterIdentityNamePropertyChanged();
        public string IdentityName
        { 
            get
            {
                return _IdentityName;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _IdentityName = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _IdentityName);
                    OnBeforeIdentityNamePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("IdentityName", eventData.Value, true, true);
                        OnAfterIdentityNamePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region LogScopeId

        private long _LogScopeId;
        partial void OnBeforeLogScopeIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<long> eventData);
        partial void OnAfterLogScopeIdPropertyChanged();
        public long LogScopeId
        { 
            get
            {
                return _LogScopeId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _LogScopeId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<long> eventData = new Sidvall.Business.PropertyChangeEventData<long>(value, _LogScopeId);
                    OnBeforeLogScopeIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("LogScopeId", eventData.Value, true, true);
                        OnAfterLogScopeIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region LogScopeItemId

        private System.Nullable<long> _LogScopeItemId;
        partial void OnBeforeLogScopeItemIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData);
        partial void OnAfterLogScopeItemIdPropertyChanged();
        public System.Nullable<long> LogScopeItemId
        { 
            get
            {
                return _LogScopeItemId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _LogScopeItemId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<long>>(value, _LogScopeItemId);
                    OnBeforeLogScopeItemIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("LogScopeItemId", eventData.Value, true, true);
                        OnAfterLogScopeItemIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region Message

        private string _Message;
        partial void OnBeforeMessagePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterMessagePropertyChanged();
        public string Message
        { 
            get
            {
                return _Message;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _Message = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Message);
                    OnBeforeMessagePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("Message", eventData.Value, true, true);
                        OnAfterMessagePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region Title

        private string _Title;
        partial void OnBeforeTitlePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterTitlePropertyChanged();
        public string Title
        { 
            get
            {
                return _Title;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _Title = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Title);
                    OnBeforeTitlePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("Title", eventData.Value, true, true);
                        OnAfterTitlePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region ServerConnectionId

        private System.Nullable<System.Int32> _ServerConnectionId;
        partial void OnBeforeServerConnectionIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.Int32>> eventData);
        partial void OnAfterServerConnectionIdPropertyChanged();
        public System.Nullable<System.Int32> ServerConnectionId
        { 
            get
            {
                return _ServerConnectionId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _ServerConnectionId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<System.Int32>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.Int32>>(value, _ServerConnectionId);
                    OnBeforeServerConnectionIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("ServerConnectionId", eventData.Value, true, true);
                        OnAfterServerConnectionIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeItemManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowStateIsDirty

        protected override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeItemManager.DataRowStateIsDirty(this);
            }
        }

        #endregion
        
        public LogScope LogScope { get; set; }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public LogScopeItemCategoryCollectionItem LogScopeItemCategories { get; set; }
        #region LoadLogScopeItemCategories

        public void LoadLogScopeItemCategories(LogScopeItemCategoryCollectionItem value)
        {
            LoadInstanceField("LogScopeItemCategories", value, true, false);
        }

        #endregion
        #region LoadLogScopeItemCategoriesAsync

        public async System.Threading.Tasks.Task<LogScopeItemCategoryCollectionItem> LoadLogScopeItemCategoriesAsync()
        {
            return await LoadLogScopeItemCategoriesAsync(false, true, null, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<LogScopeItemCategoryCollectionItem> LoadLogScopeItemCategoriesAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchListCriteria<global::Sidvall.LogManager.Data.Fields.LogScopeItemCategoryField, global::Sidvall.LogManager.Data.Relations.LogScopeItemCategoryRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.LogManager.SystemContext.Current.DataPortal.LogScopeItemManager.LoadLogScopeItemCategoriesAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters).ConfigureAwait(false);

            return this.LogScopeItemCategories;
        }

        #endregion
        #region LoadLogScopeAsync

        public async System.Threading.Tasks.Task<LogScope> LoadLogScopeAsync()
        {
            return await LoadLogScopeAsync(false, true, null, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<LogScope> LoadLogScopeAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchCriteria<global::Sidvall.LogManager.Data.Fields.LogScopeField, global::Sidvall.LogManager.Data.Relations.LogScopeRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.LogManager.SystemContext.Current.DataPortal.LogScopeItemManager.LoadLogScopeAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters).ConfigureAwait(false);

            return this.LogScope;
        }
        public LogScope LoadLogScope(LogScope item)
        {
            LoadInstanceField("LogScope", item, true, false);
            return item;
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool updateState)
        {
            global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeItemManager.LoadInstanceField(this, fieldName, value, cascade, false, updateState);
        }

        #endregion
        #region Copy

        public LogScopeItem Copy()
        {
            return global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeItemManager.Copy(this);
        }
        public LogScopeItem Copy(Sidvall.Data.CopySettings settings)
        {
            return global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeItemManager.Copy(this, settings);
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.LogManager.Data.ILogScopeItem item)
        {
            global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeItemManager.Import(this, item);
        }
        public void Import(global::Sidvall.LogManager.Data.ILogScopeItem item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeItemManager.Import(this, item, settings);
        }

        #endregion
        #region SaveItemAsync

        public async System.Threading.Tasks.Task<LogScopeItem> SaveItemAsync()
        {
            return await global::Sidvall.LogManager.SystemContext.Current.DataPortal.LogScopeItemManager.SaveItemAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<LogScopeItem> SaveItemAsync(Sidvall.Data.SaveMode mode)
        {
            return await global::Sidvall.LogManager.SystemContext.Current.DataPortal.LogScopeItemManager.SaveItemAsync(this, mode).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<LogScopeItem> SaveItemAsync(Sidvall.Data.SaveSettings settings)
        {
            return await global::Sidvall.LogManager.SystemContext.Current.DataPortal.LogScopeItemManager.SaveItemAsync(this, settings).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<LogScopeItem> SaveItemAsync(Sidvall.Data.SaveSettings settings, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            return await global::Sidvall.LogManager.SystemContext.Current.DataPortal.LogScopeItemManager.SaveItemAsync(this, settings, strategyContext, objectParameters).ConfigureAwait(false);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeItemManager.ValidateAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            return await global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeItemManager.ValidateAsync(this, settings).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeItemManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeItemManager.Initialize(this, settings);
        }

        #endregion

        #region ILogScopeItem Members

        System.DateTime global::Sidvall.LogManager.Data.ILogScopeItem.CreatedTime
        {
            get
            {
                return this._CreatedTime;
            }
            set
            {
                this._CreatedTime = value;
            }
        }
        global::Sidvall.Logging.EventType global::Sidvall.LogManager.Data.ILogScopeItem.EventTypeId
        {
            get
            {
                return this._EventTypeId;
            }
            set
            {
                this._EventTypeId = value;
            }
        }
        string global::Sidvall.LogManager.Data.ILogScopeItem.IdentityAuthenticationType
        {
            get
            {
                return this._IdentityAuthenticationType;
            }
            set
            {
                this._IdentityAuthenticationType = value;
            }
        }
        string global::Sidvall.LogManager.Data.ILogScopeItem.IdentityName
        {
            get
            {
                return this._IdentityName;
            }
            set
            {
                this._IdentityName = value;
            }
        }
        long global::Sidvall.LogManager.Data.ILogScopeItem.LogScopeId
        {
            get
            {
                return this._LogScopeId;
            }
            set
            {
                this._LogScopeId = value;
            }
        }
        System.Nullable<long> global::Sidvall.LogManager.Data.ILogScopeItem.LogScopeItemId
        {
            get
            {
                return this._LogScopeItemId;
            }
            set
            {
                this._LogScopeItemId = value;
            }
        }
        string global::Sidvall.LogManager.Data.ILogScopeItem.Message
        {
            get
            {
                return this._Message;
            }
            set
            {
                this._Message = value;
            }
        }
        string global::Sidvall.LogManager.Data.ILogScopeItem.Title
        {
            get
            {
                return this._Title;
            }
            set
            {
                this._Title = value;
            }
        }
        System.Nullable<System.Int32> global::Sidvall.LogManager.Data.ILogScopeItem.ServerConnectionId
        {
            get
            {
                return this._ServerConnectionId;
            }
            set
            {
                this._ServerConnectionId = value;
            }
        }
        global::Sidvall.LogManager.Data.ILogScope global::Sidvall.LogManager.Data.ILogScopeItem.LogScope
        {
            get
            {
                return this.LogScope;
            }
            set
            {
                this.LogScope = (LogScope)value;
            }
        }
        System.Collections.Generic.IEnumerable<global::Sidvall.LogManager.Data.ILogScopeItemCategory> global::Sidvall.LogManager.Data.ILogScopeItem.LogScopeItemCategories
        {
            get
            {
                if (this.LogScopeItemCategories != null)
                    return this.LogScopeItemCategories.Items;
                return null;
            }
        }
        void global::Sidvall.LogManager.Data.ILogScopeItem.SetLogScopeItemCategories(Sidvall.Data.IDataRowProvider<global::Sidvall.LogManager.Data.ILogScopeItemCategory> items)
        {
            this.LogScopeItemCategories = (LogScopeItemCategoryCollectionItem)items;
        }

        #endregion

        #endregion
        #region Constructors

        public LogScopeItem()
        {
        }
        public LogScopeItem(bool initializeDefaultValues)
            : this(initializeDefaultValues, null, Sidvall.Business.BusinessEvents.None)
        {
        }
        public LogScopeItem(bool initializeDefaultValues, Sidvall.Data.DataRowState? dataRowState, Sidvall.Business.BusinessEvents enabledBusinessEvents)
            : base(dataRowState, enabledBusinessEvents)
        {
            if (initializeDefaultValues)
                global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeItemManager.Initialize(this);
        }

        #endregion
    }
}